package sctu.edu.java.year2016.team01.lishuai.day20160606.chapter15_3;

/**
 * Created by 李大帅 on 2016/6/11.
 * 尝试开发一个窗体，在窗体中设计一个进度条，是进度条每次递增滚动。
 */

import javax.swing.*;
import java.awt.*;
public class ProgressBar extends JFrame{

    private Thread thread;
    final JProgressBar progressBar = new JProgressBar();
    int count = 0;

    public static void main(String[] args) {

        init(new ProgressBar(),100,100);
    }

    public ProgressBar()
    {
        super();
        getContentPane().add(progressBar, BorderLayout.NORTH);
        progressBar.setStringPainted(true);

        thread = new Thread(new Runnable() {

            int count = 0;
            public void run() {

                while (true)
                {
                    progressBar.setValue(++count);
                    try
                    {
                        thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread.start();
    }

    public static void init(JFrame frame,int width,int height)
    {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width,height);
        frame.setVisible(true);
    }
}

